<?php

namespace app\model;
use think\Db;

use app\model\StationBoxOrder as ModelStationBoxOrder;
use app\model\StationBoxOrderLog as ModelStationBoxOrderLog;

class StationBoxOrderLog extends Common
{
    protected static $obj;

    public function _initialize()
    {
        parent::_initialize();
        $this->db_name = 'station_box_order_log';
    }

    /**
     * 类入口
     * @return StationBoxOrderLog
     */
    public static function getInstance()
    {
        if (is_null(self::$obj))
            self::$obj = new self();
        return self::$obj;
    }

    /**
     * @param $str_box_order_number
     * @param $str_remark
     * @return string
     */
    public function  StationOrderLogAdd($str_box_order_number, $str_remark)
    {
        $data['box_order_id'] = (int)ModelStationBoxOrder::getInstance()->toValue(['box_order_number' => $str_box_order_number], 'id');
        $data['box_order_number'] = (string)ModelStationBoxOrder::getInstance()->toValue(['box_order_number' => $str_box_order_number], 'box_order_number');;
        $data['type'] = 2;
        $data['remark'] = $str_remark;
        $data['station_id'] = (int)ModelStationBoxOrderLog::getInstance()->toValue(['box_order_number' => $str_box_order_number], 'station_id');
        $data['mobile'] = (string)ModelStationBoxOrderLog::getInstance()->toValue(['box_order_number' => $str_box_order_number], 'mobile');
        $data['operator'] = (string)ModelStationBoxOrderLog::getInstance()->toValue(['box_order_number' => $str_box_order_number], 'operator');
        $data['state'] = (int)ModelStationBoxOrderLog::getInstance()->toValue(['box_order_number' => $str_box_order_number], 'state');
        return $this->toAdd($data);

    }
    /**
     * 业务信息->拆装箱列表分页总数
     * @param array $where
     * @param string $field
     * @param null $firstRow
     * @param null $listRows
     * @param null $order
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function toLeftJoinCount($where = [])
    {
        return Db::name($this->db_name)->where($where)->group("DATE_FORMAT(gmt_create,'%Y-%m-%d')")->count();
    }

    /**
     * 业务信息->拆装箱列表
     * @param array $where
     * @param string $field
     * @param null $firstRow
     * @param null $listRows
     * @param null $order
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function toLeftJoinSelect($where = [], $field = '*', $firstRow = null, $listRows = null, $order = null)
    {
        return Db::name($this->db_name)->field($field)->where($where)->limit($firstRow, $listRows)->group("substr(gmt_create,1,10)")->order($order)->select();
    }


}